package com.kxz.Controller;

import com.kxz.pojo.Grade;
import com.kxz.repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class GradeController {
    @Autowired
    GradeRepository gradeRepository;

    //增
    @PostMapping("/grade")
    public Grade add(Grade grade){
        Grade grade1=gradeRepository.save(grade);
        return grade1;
    }
    //删
    @DeleteMapping("/grade/{gid}")
    public void del(@PathVariable("gid") Integer gid){
        gradeRepository.deleteById(gid);
    }
    //改
    @PutMapping("/grade")
    public Grade updateGrade(Grade grade){
        Grade grade1 =gradeRepository.save(grade);
        return grade1;
    }
    //查
    @GetMapping("/grade/{gid}")
    public Grade getGrade(@PathVariable("gid") Integer gid){
        Grade grade=gradeRepository.findById(gid).get();
        return grade;
    }
}
